package com.xlh.general;

import com.xlh.api.Dictionary;
import ro.fortsoft.pf4j.Extension;
import ro.fortsoft.pf4j.Plugin;
import ro.fortsoft.pf4j.PluginException;
import ro.fortsoft.pf4j.PluginWrapper;

import java.util.SortedMap;
import java.util.TreeMap;

/**
 * @author xulihua
 * @date 2021/9/26 16:05
 */
public class GeneralPlugin extends Plugin {

    public GeneralPlugin(PluginWrapper wrapper) {
        super(wrapper);
    }

    @Override
    public void start() throws PluginException {
        log.info("GeneralPlugin start....");
        super.start();
    }

    @Override
    public void stop() throws PluginException {
        log.info("GeneralPlugin stop....");
        super.stop();
    }

    @Extension
    public static class GeneralDictionary implements Dictionary {
        /**
         * 字典存储的内容
         */
        private final SortedMap<String, String> map = new TreeMap<>();

        /**
         * 构造时即创建字典内容
         */
        public GeneralDictionary() {
            map.put(
                    "book",
                    "a set of written or printed pages, usually bound with " +
                            "a protective cover");
            map.put(
                    "editor",
                    "a person who edits");
        }

        @Override
        public String getDefinition(String word) {
            return map.get(word);
        }
    }
}
